package com.xinjian.jianba.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xinjian.jianba.dto.UserLocationDto;
import com.xinjian.jianba.exception.ResponseCode;
import com.xinjian.jianba.service.UserLocationService;
import com.xinjian.jianba.utils.JsonUtil;
import com.xinjian.jianba.utils.LogBuilder;
import com.xinjian.jianba.utils.ModuleEnum;

@RestController
@RequestMapping("/api/v3/jianba/location")
public class LocationController extends AbstractController {

	private static final Logger LOGGER = LoggerFactory.getLogger(LocationController.class);

	@Autowired
	private UserLocationService userLocationService;

	@PostMapping(value = { "/save" })
	public String register(@RequestBody UserLocationDto userLocation) {
		LOGGER.info(LogBuilder.build(ModuleEnum.LOCATION, "用户位置,参数 userLocation={}"), JsonUtil.getJsonString(userLocation));
		if (userLocation == null) {
			return this.responseClientJsonData(ResponseCode.BAD_REQUEST, ResponseCode.PARAM_ERROR_MSG);
		}
		try {
			userLocationService.save(userLocation);
			return this.responseClientJsonData(ResponseCode.SUCCESS, ResponseCode.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			return this.responseClientJsonData(ResponseCode.SUCCESS, ResponseCode.SUCCESS_MSG);
		}
	}

}